class HomeController < ApplicationController
require 'net/http'
require 'rexml/document'
require 'json'

include REXML

def concerto_parse()
    concerto_site = "concerto.rpi.edu"
    concerto_feed = "/content/render/?select_id=1"

    web_xml = ''

    Net::HTTP.start(concerto_site) do |http|
        web_xml = http.get(concerto_feed)
        end

    id_regexp = Regexp.new('image_(\d+)\..*\?')

    idNamePairs = []

    doc, statuses = REXML::Document.new(web_xml.body), []
    doc.elements.each('rss/channel/item') do |item|

        # credit for html tag stripping goes to:
        # http://codesnippets.joyent.com/posts/show/615
        a_title = item.elements['title'].to_s.gsub(/<\/?[^>]*>/, "")

        content = item.elements['media:content'].to_s
        an_id = id_regexp.match(content)
        if an_id != nil
            idNamePairs.push( [an_id.captures.to_s, a_title] )
        else
            puts "Skipping item "+a_title+": no media:content image"
        end
    end

    return idNamePairs
end

  def index
    @s_events = "[['1900','2000','Coding','20100422'],['2000','2100','Coding II','20100422'],['2200','2300','Coding III','20100422'],['2300','2400','God I Hope This is Done Soon','20100422']]"
    @c_feed = concerto_parse().to_json
  end

end
